package com.Rolin.wss.controller;

import com.Rolin.wss.dao.MealMapper;
import com.Rolin.wss.model.JspToController.ChooseFreeO;
import com.Rolin.wss.model.JspToController.ChooseProO;
import com.Rolin.wss.service.FlightService;
import com.Rolin.wss.service.MealService;
import com.Rolin.wss.util.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/meals")
public class MealController {
    @Autowired
    private MealService mealService;
    @Autowired
    private FlightService flightService;

    @RequestMapping(value = "free.do",method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String userSelectionFreeMeal(@RequestBody ChooseFreeO cfo){
        if(!mealService.buyFreeMeal(cfo.getUserID(), cfo.getTicketID(), cfo.getFreeID())){
            return utils.buildJSONForReturn(1,"购买出错！");
        }else{
            int foodID = mealService.getOrderedAMeal(cfo.getTicketID()).getMo_food1();
            String food = mealService.getMeal(foodID).getMeal_name();
            return utils.buildJSONForReturn(0,"购买成功，购买的餐饮是："+food);
        }
    }


    @RequestMapping(value = "pro.do",method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String userSelectionProMeal(@RequestBody ChooseProO cpo){
        if(mealService.buyProMeal(cpo)){
            return utils.buildJSONForReturn(0,"购买成功");
        }else{
            return utils.buildJSONForReturn(1,"购买失败，请联系系统管理员");
        }
    }

}
